﻿using System;

namespace MathService.DSP
{
    public static class SimpleSignalGenerator
    {
        public static double[] CreateSignal(Converter<double, double> Function, double dt, int Length)
        {
            var lv_Result = new double[Length];

            for(var i = 0; i < Length; i++)
                lv_Result[i] = Function(i * dt);

            return lv_Result;
        }

        public static double[] Exponential(double A, double alpha, double t0, double s0, double dt, int Length)
        {
            return CreateSignal(t => A * Math.Exp(alpha * (t - t0)) + s0, dt, Length);
        }

        public static double Pulse(double A, double t0, double t1, double t2, double t)
        {
            t -= t0;
            return t > t1 && t < t2
                ? A
                : (t.Equals(t1) || t.Equals(t2) ? A / 2 : 0);
        }

        public static double[] Impulse_Single(double A, double t0, double t1, double t2, double dt, int Length)
        {
            return CreateSignal(t => Pulse(A, t0, t1, t2, t), dt, Length);
        }

        public static double Trapeze(double A, double t0, double t1, double t2, double t3, double t)
        {
            return t < t0 || t > t3
                ? 0
                : (t >= t1 && t <= t2
                    ? A
                    : (t >= t0 && t < t1
                        ? (t - t0) / (t1 - t0) * A
                        : (t - t3) / (t2 - t3) * A));
        }

        public static double[] Traperiform_Signal(double A, double t0, double t1, double t2, double t3, double dt,
            int Length)
        {
            return CreateSignal(t => Trapeze(A, t0, t1, t2, t3, t), dt, Length);
        }
    }
}
